﻿using System.Collections.Generic;

namespace WFRPDice
{
    public class DiceRollResult : List<DiceSymbol>
    {
        //Scope for the constructor's list
        public List<DiceSymbol> RollResults;

        #region CountProperties

        public int Success { get; private set; }

        public int DoubleSuccess { get; private set; }

        public int BoonSuccess { get; private set; }

        public int ExertionSuccess { get; private set; }

        public int DelaySuccess { get; private set; }

        public int Challenge { get; private set; }

        public int DoubleChallenge { get; private set; }

        public int Blank { get; private set; }

        public int Boon { get; private set; }

        public int DoubleBoon { get; private set; }

        public int Bane { get; private set; }

        public int DoubleBane { get; private set; }

        public int SigmarsComet { get; private set; }

        public int ChaosStar { get; private set; }

        public int Delay { get; private set; }

        public int Exertion { get; private set; }

        #endregion

        #region Calculated Properties

        public int TotalSuccess { get; private set; }

        public int TotalChallenges { get; private set; }

        public int TotalBoons { get; private set; }

        public int TotalBanes { get; private set; }

        public int TotalExertions { get; private set; }

        public int TotalDelays { get; private set; }

        public int NetSuccess { get; private set; }

        public int NetBoons { get; private set; }

        #endregion

        //Constructor
        public DiceRollResult(List<DiceSymbol> rollResults)
        {
            CountResultSymbols(rollResults);
            CalculateResultSymbols();
        }

        //Calculate some important info here so we don't have to do it elsewhere.
        //This is the kind of stuff a result should know about itself, anyway.
        private void CalculateResultSymbols()
        {
            TotalSuccess = Success + (DoubleSuccess*2) + BoonSuccess + DelaySuccess + ExertionSuccess + SigmarsComet;
            TotalChallenges = Challenge + (DoubleChallenge*2) + ChaosStar;
            TotalBoons = Boon + (DoubleBoon*2) + BoonSuccess;
            TotalBanes = Bane + (DoubleBane*2);
            TotalDelays = Delay + DelaySuccess;
            TotalExertions = Exertion + ExertionSuccess;

            //Did we succeed?!
            NetSuccess = TotalSuccess - TotalChallenges;
            NetBoons = TotalBoons - TotalBanes;
        }

        //Use the GetDiceSymbolCount tool below to populate each of the counting properties, above.
        //I'm sure there's a way to loop through each int via reflection and do this, but I don't
        //know it.
        public void CountResultSymbols(List<DiceSymbol> rResults)
        {
            RollResults = rResults;
            Bane = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.Bane, RollResults);
            Blank = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.Blank, RollResults);
            Boon = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.Boon, RollResults);
            BoonSuccess = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.BoonSuccess, RollResults);
            Challenge = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.Challenge, RollResults);
            SigmarsComet = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.SigmarsComet, RollResults);
            Delay = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.Delay, RollResults);
            DelaySuccess = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.DelaySuccess, RollResults);
            DoubleBane = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.DoubleBane, RollResults);
            DoubleBoon = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.DoubleBoon, RollResults);
            DoubleChallenge = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.DoubleChallenge, RollResults);
            DoubleSuccess = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.DoubleSuccess, RollResults);
            Exertion = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.Exertion, RollResults);
            ExertionSuccess = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.ExertionSuccess, RollResults);
            ChaosStar = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.ChaosStar, RollResults);
            Success = WfrpDiceHelper.GetDiceSymbolCount(DiceSymbol.Success, RollResults);
        }

        public override string ToString()
        {
            //return base.ToString();
            return string.Format("{0}  {1}  {2}  {3}  {4}  {5}  {6}  {7}", TotalSuccess,
                                 TotalChallenges.ToString(), TotalBoons.ToString(), TotalBanes.ToString(),
                                 TotalDelays.ToString(), TotalExertions.ToString(), ChaosStar.ToString(), SigmarsComet.ToString()) ;
        }
    }
}